******************************************
*
*	Article: The Human Costs of the War on Drugs: Attitudes towards Militarization of Security in Mexico
*	Authors: Juan Masullo J., Davide Morisi
*	Journal: Comparative Political Studies
*	Date: 23 March 2023
*
*	This file replicates the following
*	MERGING INDIVIDUAL DATA WITH MUNICIPALITY-LEVEL DATA - STUDY 2
*
*	All analyses performed with Stata/SE 14.2 for Windows
******************************************

*Set working directory
*[my working directory]

/*Open original dataset Study 2
use "Replication_CPS\Data\study2.dta", clear


****
*Merging with data at municipality level

*Merge with population data (2010)
*Source: INEGI, 2010 census
merge m:1 inegi_code using "Replication_CPS\Data\population2010.dta" 
drop if _merge==2
drop _merge

*Merge with homicide data (2013-2017)
*Source: INEGI
merge m:1 inegi_code using "Replication_CPS\Data\homicides.dta"
drop if _merge==2
drop _merge

*Merge with cartel presence data (2013-2017)
*Source: Sobrino, Fernanda. 2020. "Mexican Cartel Wars: Fighting for the U.S. Opioid Market". www.fersobrino.com/files/DraftPaper.pdf (Visited on 07/12/2020)
merge m:1 inegi_code using "Replication_CPS\Data\cartel_presence.dta"
drop if _merge==2
drop _merge

********
*Recode homicide rate (2013-2017)

*Homicide rate every 10K people per year (on average), 2013-2107
gen hom_1317_pop = (((hom_2013 + hom_2014 + hom_2015 + hom_2016 + hom_2017)/5)*10000)/pop_tot_2010
sum hom_1317_pop, d

*Winsorize variable at 95th pctile
winsor2 hom_1317_pop, cuts(0 95)
sum hom_1317_pop_w, d


********
*Remove municipality identifiers for anonymity reasons

drop municipality_name inegi_code pop_tot_2010
save "Replication_CPS\Data\study2_privacy.dta", replace

use "Replication_CPS\Data\population2010.dta", clear
drop inegi_code
save "Replication_CPS\Data\population2010_privacy.dta", replace

use "Replication_CPS\Data\homicides.dta", clear
drop inegi_code
save "Replication_CPS\Data\homicides_privacy.dta", replace

use "Replication_CPS\Data\cartel_presence.dta", clear
drop inegi_code
save "Replication_CPS\Data\cartel_presence_privacy.dta", replace

